package com.mp.ipm2020.admin.controller;

import com.mp.ipm2020.common.api.CommonResult;
import com.mp.ipm2020.mbg.model.Control;
import com.mp.ipm2020.mbg.model.DeviceData;
import com.mp.ipm2020.mbg.model.Value;
import com.mp.ipm2020.mbg.service.ValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Auther adidasshe@mp.cn
 * <p>
 * 阈值 controller
 */
@Api(tags = "阈值控制")
@RestController
@RequestMapping("/value")
public class ValueController {
    @Autowired
    private ValueService valueService;

    @ApiOperation("添加阈值")
    @PostMapping
    public CommonResult create(@RequestBody Value value) {
        value.setCreateTime(new Date());
        boolean count = valueService.saveOrUpdate(value);
        if (count == true) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("根据设备ID查询阈值")
    @GetMapping("/{device_id}")
    public CommonResult getItem(@PathVariable(value = "device_id", required = false) String device_id) {
        Value data = valueService.getByDeviceId(device_id);
        return CommonResult.success(data);
    }
}
